package edu.java.ishop.services;

import javax.inject.Inject;
import javax.inject.Named;

import edu.java.ishop.dao.UserDao;
import edu.java.ishop.dao.UserRoleDao;
import edu.java.ishop.model.User;
import edu.java.ishop.model.UserRole;
import edu.java.ishop.utils.PasswordHelper;

@Named
public class UserService {

	@Inject
	private UserDao userDao;
	@Inject
	private UserRoleDao userRoleDao;
	public UserService(){
		
	}
	public boolean isLogged(String username,String password){
		return userDao.getByUsernamePassword(username, password) != null;
	}
	
	public UserRole getPrincipal(String username,String password){
		User user = userDao.getByUsernamePassword(username,PasswordHelper.hash(password));
		if(user != null){
			return userRoleDao.getByUserId(user.getId());
		}
		return null;
	}
}
